﻿using System.Collections.Generic;
using System.Linq;
using BattleBotsMattAndSunny.Components.Interfaces;
using BattleBotsMattAndSunny.Model;
using Robocode;

namespace BattleBotsMattAndSunny.Components.Data
{
    public class DataManager : IDataManager
    {
        public string CurrentTargetName { get; set; }

        private List<ScannedRobotEvent> Scans { get; set; }

        private List<Bullet> FiredBullets { get; set; }

        private List<Enemy> Enemies { get; set; }

        public DataManager()
        {
            Scans = new List<ScannedRobotEvent>();
            FiredBullets = new List<Bullet>();
            Enemies = new List<Enemy>();
        }

        public ScannedRobotEvent GetLastScan()
        {
            return Scans.Count > 0 ? Scans.Last() : null;
        }

        public Bullet GetLastBulletFired()
        {
            return FiredBullets.Count > 0 ? FiredBullets.Last() : null;
        }

        public void StoreBullet(Bullet b)
        {
            FiredBullets.Add(b);
        }

        public void StoreEnemy(Enemy e)
        {
            Enemies.Add(e);
        }

        public void StoreScan(ScannedRobotEvent s)
        {
            Scans.Add(s);
        }

        public Enemy GetCurrentTarget()
        {
            return Enemies.FirstOrDefault(x => x.Name == CurrentTargetName);
        }

        public Enemy GetEnemy(string enemyName)
        {
            return Enemies.FirstOrDefault(x => x.Name == enemyName);
        }
    }
}